﻿using System;
using System.Collections.Generic;

namespace AppMain
{

    public class RoleAttrMap : IAttrMap
    {
        Dictionary<short, IAttr> map = new Dictionary<short, IAttr>();

        public BaseAttr<T> getAttr<T>(short attrType) where T : IEquatable<T>
        {
            IAttr attr;
            if (!map.TryGetValue(attrType, out attr))
            {
                attr = new BaseAttr<T>(attrType, default(T));
                map.Add(attrType, attr);
            }
            return attr as BaseAttr<T>;
        }

        public void changeAttr<T>(short attrType, T value) where T : IEquatable<T>
        {
            IAttr attr;
            if (!map.TryGetValue(attrType, out attr))
            {
                attr = new BaseAttr<T>(attrType, default(T));
                map.Add(attrType, attr);
            }
            BaseAttr<T> baseAttr = attr as BaseAttr<T>;
            baseAttr.Value = value;
        }

    }
}

